function Tentamen(a_scores)
{
    var resultString = "All scores: " + a_scores + "<br />";
    
    var mean = GetMean(a_scores); 
    
    var highScore = GetHighestScore(a_scores);
    
    var lowestScore = GetLowestScore(a_scores);
    
    var results = [mean, highScore, lowestScore];
    
    // Used to present the results.
    resultString += "Mean: " + mean + "<br />" + 
                    "Highscore: " + highScore + "<br />" + 
                    "Lowest score: " + lowestScore + "<br />" +
                    "Result array: " + results;
    
    document.getElementById("results").innerHTML=resultString;
    
    return results;
}


// Get the highest score from all
// the results.
function GetHighestScore(a_scores)
{
    // Sort the array in descending order so we get the highest score first.
    var sortedScores = a_scores.sort(function(a,b){return b-a});
    
    // Get the score from the first element in the array(contains the highest score).
    var highScore = a_scores[0];
    
    return highScore;
}

// Get the lowest score from all
// the results.
function GetLowestScore(a_scores)
{
    // Sort the array in ascending order so we get the lowest score first.
    var sortedScores = a_scores.sort(function(a,b){return a-b});
    
    // Get the score from the first element in the array(contains the lowest score).
    var lowestScore = a_scores[0];
    
    return lowestScore; 
}

// Sums all the scores and returns
// the mean from all the scores.
function GetMean(a_scores)
{
    var mean = 0;
    var sum = 0;
    
    // As long as there is still a score left in the 
    // results add it to the total sum of all the scores.
    for (i = 0; i < a_scores.length; i++)
    {
        sum += a_scores[i];
    }
    
    // Get the mean from all the scores.
    mean = sum/i;
    
    return mean;   
}